<?php

/**
 * 返回提示信息
 * @param $str
 * @param $backurl
 * @param int $time
 * @return string
 */
function showMsg($str, $backurl = '-1', $time = 2000)
{
    $str_build = '<div id="msg" style="width:300px;margin:0px auto;text-align: center;padding:10px;border:1px solid #ccc">';
    $str_build .= '<h3>提示信息</h3>';
    $str_build .= '<p>' . $str . '</p>';
    if($backurl=='-1'){
      $str_build .= '<p><a href="javascript:window.history.back();">返回</a></p>';
    }else{
      $str_build .= '<p><a href="javascript:window.location.href=\''.$backurl.'\'">返回</a></p>';
    }
    $str_build .= '</div>';
    $str_build.='<script type="text/javascript">';
    if($backurl=='-1')
    {
      $str_build.='setTimeout(function(){window.history.go(-1);},'.$time.')';
    }else{
      $str_build.='setTimeout(function(){window.location.href=\''.$backurl.'\';},'.$time.')';
    }
    $str_build.='</script>';
    return $str_build;
}

/**
 * 创建指定目录
 * @param $path
 */
function CreateDire($path)
{
    if(!is_dir($path))
    {
        $dirs = array();
        //loop through path parts
        foreach (explode("/", $path) as $dir) {
            $dirs[] = $dir;

            //don't attempt anything when empty (always the first `/`)
            if ($dir) {
                //check if dir already exists
                if (!is_dir(implode("/", $dirs))) {
                    //do it all
                    mkdir(implode("/", $dirs));
                    chgrp(implode("/", $dirs), "www-data");
                    chmod(implode("/", $dirs), 0777);
                }
            }
        }
    }
}

/**
 * 生成一个长度为16位的随机字符串
 */
function RandNumber()
{
    $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
    $Sn = $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
    return $Sn;
}

/**
 * 获取文件扩展名
 * @param $file
 * @return mixed
 */
function get_extension($file)
{
    return pathinfo($file, PATHINFO_EXTENSION);
}
?>